package com.mf.morefun.receiver;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.zhcx.zhcxlibrary.utils.ToastUtils;

import static android.content.Context.CONNECTIVITY_SERVICE;

public class NetReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if(action.equals(ConnectivityManager.CONNECTIVITY_ACTION)){//监控网络
            //检查网络状态的类型
            int netWrokState = NetUtil.getNetWorkState(context);
            if (netWrokState == -1){//这里就有网络
                if (null != context){
                    ToastUtils.show(context, "清打开网络", 100);
                }
            }
        }
    }
}
